﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract  class Soldier : Character {
    private SoldierFSMSystem m_fsmSystem;
    public Soldier()
    {
        //构造方法
        //初始化 状态机
        MakeFSM(); 
    }

  
    /// <summary>
    /// 更新AI中的状态
    /// </summary>
    /// <param name="targets"></param>
    public override void UpdateFSMAI(List<Character> targets)
    {
        m_fsmSystem.currentState.Reason(targets);
        m_fsmSystem.currentState.Act(targets);
    }


    protected void MakeFSM()
    {
        m_fsmSystem = new SoldierFSMSystem();

        SoldierIdleState idleState = new SoldierIdleState(m_fsmSystem, this);
        idleState.AddTransition(SoldierTrasition.CanSeeEnemey, SoldierStateID.Chase);

        SoldierChaseState chaseState = new SoldierChaseState(m_fsmSystem, this);
        chaseState.AddTransition(SoldierTrasition.LostEnemy, SoldierStateID.Idle);
        chaseState.AddTransition(SoldierTrasition.InAttackDistance, SoldierStateID.Attack);

        SoldierAttackState attackState = new SoldierAttackState(m_fsmSystem, this);
        attackState.AddTransition(SoldierTrasition.LostEnemy, SoldierStateID.Idle);
        attackState.AddTransition(SoldierTrasition.CanSeeEnemey, SoldierStateID.Chase);

        m_fsmSystem.AddState(idleState, chaseState, attackState);

    }



    public override void UnderAttack(float dmg)
    {
        base.UnderAttack(dmg);
        if (m_attr.CurrentHP <= 0)
        {
            PlaySound(m_attr.AudioName);
            PlayEffect(m_attr.EffectName);
            Killed();
        }
    }
   

}
